<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class ModuleManageDeleteCommand extends Command
{
    /**
     * command name
     */
    protected $signature = 'ModuleManage:delete {moduleName}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Module manager delete module.';

    /**
     * Handle Function!
     */
    public function handle()
    {
        $moduleName = $this->argument('moduleName');
        $ControllerPath = base_path('app/Http/Controllers/'.$moduleName);
        $MiddlewarePath = base_path('app/Http/Middleware/'.$moduleName);
        $ValidatorsPath = base_path('app/Http/Validators/'.$moduleName);
        $ConsolePath = base_path('app/Console/Commands/'.$moduleName);
        $ModelsPath = base_path('app/Models/'.$moduleName);

        try {
            is_dir($ControllerPath) && DeleteDir($ControllerPath);
            is_dir($MiddlewarePath) && DeleteDir($MiddlewarePath);
            is_dir($ValidatorsPath) && DeleteDir($ValidatorsPath);
            is_dir($ConsolePath) && DeleteDir($ConsolePath);
            is_dir($ModelsPath) && DeleteDir($ModelsPath);
            echo "Delete module {$moduleName} success!" . PHP_EOL;
        } catch (\Throwable $exception) {
            throw new \Exception($exception->getMessage());
        }
    }
}
